rm(list = ls())

library(ggplot2)

# Purpose: Plot average coherence and average FREX

### PATHS ##############################
in.path <- "./data/"
#######################################

best.model <- 22

for (weight in c("0.5", "0.7", "1.0")) {
    for (no.words in c(5, 10, 15, 20)) {
        # load data
        w <- gsub("\\.","_",as.character(weight))
        fname <- paste0(in.path, "avg_coherence_FREX_top_",no.words,"_words_weight_",w,".RData")
        load(fname)

        # coordinate of model 27 (best performing model) to draw circle around number
        x.best <- avg$mean.coherence[avg$topic==best.model]
        y.best <- avg$mean.frex[avg$topic==best.model]
        
        # generate plot
        fname <- paste0("./plots/semantic_coherence_vs_exclusivity_top_", no.words, "_w",w,".pdf")
        pdf(fname)
            plot(avg$mean.coherence, avg$mean.frex,
                 pch="",
                 xlab="Semantic Coherence",
                 ylab="Exclusivity")
            text(avg$mean.coherence, avg$mean.frex, avg$topic)
            abline(v=mean(avg$mean.coherence), lty="dashed")
            abline(h=mean(avg$mean.frex), , lty="dashed")
            abline(lm(avg$mean.frex ~ avg$mean.coherence), col="red")
            points(x = x.best, y = y.best, col = "red", pch = 1, cex = 4)
        dev.off()
    }
}

